<template>
  <div class="manage">
    <CommonTable
      :tableData="tableData"
      :tableLabel="tableLabel"
      :config="config"
      @changePage="findPage"
      @del="delTransactLog"
    ></CommonTable>
  </div>
</template>

<script>
import CommonTable from "@/components/common/Table.vue";
export default {
  components: {
    CommonTable
  },
  data() {
    return {
      isShow: false,

      tableData: [],
      tableLabel: [
        { prop: "id", label: "ID" },

        {
          prop: "goodsName",
          label: "商品"
        },
        {
          prop: "time",
          label: "交易时间"
        },
        {
          prop: "price",
          label: "价格"
        },
        {
          prop: "num",
          label: "数量"
        }
      ],
      config: {
        currentPage: 1,
        pageSize: 7,
        total: 2,
        loading: false,
        control: false
      }
    };
  },
  methods: {
    //无误获取参数
    findPage: function() {
      let pageRequest = {
        pageNumber: this.config.currentPage,
        pageSize: this.config.pageSize
      };
      this.config.loading = true;
      this.$http.transactLog
        .findPage(pageRequest)
        .then(res => {
          this.tableData = res.content;
          this.config.total = res.totalElements;
          this.config.loading = false;
        })
        .catch(error => {
          console.log(error);
        });
    },
    delTransactLog(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http.transactLog.delTransactLog(row.id).then(res => {
            console.log(res);
            this.$message({
              type: "success",
              message: "删除成功!"
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    editTransactLog(row) {
      this.operateType = "edit";
      this.isShow = true;
      this.operateFrom = row;
    },
    confirm() {
      if (this.operateType === "edit") {
        this.$http.transactLog.update(this.operateFrom).then(res => {
          console.log(res);
          this.isShow = false;
          this.findPage(); //编辑成功后需要重新刷新用户信息
        });
      }
    }
  },
  created() {
    //创建将数据请求发出
    this.findPage();
  }
};
</script>

<style lang="scss" scoped>
@import "~@/styles/manage.scss";
</style>
